﻿using System;
using System.Collections;
using Global.Data;
using UnityEngine;

namespace Global.Manager
{
    /// <summary>
    /// 游戏场景管理
    /// </summary>
    public class GameSceneManager
    {
        private static GameSceneManager _instance;
        public static GameSceneManager Instance
        {
            get { return _instance ?? (_instance = new GameSceneManager()); }
        }
        private GameSceneState _mainSceneState;
        /// <summary>
        /// 游戏场景状态
        /// </summary>
        public GameSceneState SceneState
        {
            get { return _mainSceneState; }
        }
        /// <summary>
        /// 构造函数
        /// </summary>
        private GameSceneManager()
        {
            Init();
        }
        /// <summary>
        /// 初始化
        /// </summary>
        private void Init()
        {

        }
        /// <summary>
        /// 切换场景
        /// </summary>
        /// <param name="sceneState">场景状态</param>
        /// <param name="callBack">完成后回调函数</param>
        public void ChangeScene(GameSceneState sceneState, Action callBack = null)
        {
            _mainSceneState = sceneState;
            switch (_mainSceneState)
            {
                case GameSceneState.Altar://圣坛

                    break;
                case GameSceneState.Camp://兵营

                    break;
                case GameSceneState.Effort://成就

                    break;
                case GameSceneState.Home://家

                    break;
                case GameSceneState.Settings://游戏设置

                    break;
                case GameSceneState.Story://主线任务

                    break;
                default://圣坛

                    break;
            }
            LoadLevelAsync("Home", callBack);
        }
        /// <summary>
        /// 异步加载场景
        /// </summary>
        /// <param name="sceneName">场景名称</param>
        /// <param name="callBack">完成后回调函数</param>
        /// <returns></returns>
        private IEnumerator LoadLevelAsync(string sceneName, Action callBack = null)
        {
            var async = Application.LoadLevelAsync(sceneName);
            yield return async;
            if (callBack != null) callBack();
        }
    }
}
